/*
 * @Author: 谢小康 2170673706@qq.com
 * @Date: 2024-01-28 20:45:20
 * @LastEditors: 谢小康 2170673706@qq.com
 * @LastEditTime: 2024-01-31 11:18:45
 * @FilePath: \My-bolg\server\middleware\comment.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const Response = require("../util/respanse.js")

const verifycommentpramas = (req, res, next) => {
    try {
        let flag = false
        let { type, content, username, usersiteurl, usercover,forid,fatherid, fromid, fromname , ...item } = req.body
        if (!type || !content || !username|| !forid) {
            flag = true
            Response.errorresponse(res, {
                code: 400,
                msg: "参数错误"
            })
        }
        console.log(Object.keys(item));
        if (Object.keys(item).length>0) {
            flag = true
            Response.errorresponse(res, {
                code: 400,
                msg: "参数错误"
            })
        }
        if (!flag) {
            next()
        }
    } catch (error) {
        console.log(error);
    }
}
const verifycommentid =(req, res, next)=>{
    let {type, forid} = req.query
    let flag = false
    if (!type || !forid) {
        
        flag = true
        Response.errorresponse(res, {
            code: 400,
            msg: "参数错误"
        })
    }
    if(!flag){
        next()
    }
}
module.exports = {
    verifycommentpramas,
    verifycommentid
}